import { storage } from '../utils/storage'
import { useUserStore } from '../store/modules/user'
/**
 *
 *导航守卫
 */
const whilterList = ['/login']
//前置
export const beforeEach = (to:any, from:any, next:any) => {
    const token = storage.get('Auth-Token'); // 假设token存储在sessionStorage中
    const userStore = useUserStore()
    console.log('前置',to, from, next,'000000', userStore.Token, token)
    if (to.meta.requireAuth && whilterList.indexOf(to.path) == -1 && !userStore.Token) {
      // 如果没有token且访问的页面需要token，则重定向到登录页面
      next('/login');
    } else {
      console.log('345345')
      // 否则，继续路由
      next();
    }
  }
  
  //后置
  export const afterEach = () => {
    console.log('后置')
  }